package com.lab.spring;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: bsceran
 * Date: 5/21/13
 * Time: 11:05 AM
 * To change this template use File | Settings | File Templates.
 */
public class SequenceGenerator {
    private List<String> suffixes;
    private int initial;
    private int counter;
    private PrefixGenerator prefixGenerator;

    public SequenceGenerator() {
    }

    public SequenceGenerator(int initial) {
        this.initial = initial;
    }

    public SequenceGenerator(int initial, List<String> suffixes) {
        this.suffixes = suffixes;
        this.initial = initial;
    }

    public void setPrefixGenerator(PrefixGenerator prefixGenerator) {
        this.prefixGenerator = prefixGenerator;
    }

    public void setSuffixes(List<String> suffixes) {
        this.suffixes = suffixes;
    }

    public void setInitial(int initial) {
        this.initial = initial;
    }

    public synchronized String getSequence() {
        StringBuffer buffer = new StringBuffer();
        buffer.append(prefixGenerator.generatePrefix());
        buffer.append(initial + counter++);
        for (String suffix : suffixes) {
            buffer.append("-");
            buffer.append(suffix);
        }
        return buffer.toString();
    }


}
